<%@ page language="java" contentType="text/html;UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="com.bear.model.entity.User" %>
<%@include file="base.jsp" %>

<title>首页</title>
<script>
function open1(){
	$('#wlogin').window('open');
}
function open2(){
	$('#wregist').window('open');
}
function close1(){
	$('#wlogin').window('close');
}
function close2(){
	$('#wregist').window('close');
}
function login(){
	var a = $('#ff');
	a.submit();
}

function checkRegist()
{
	var registname = $('#registname').val();
	if(registname=="")
		{
		$('#show').html("<font color='red'>用户名不能为空</font>");
		return;
		}
	$.post("<c:url value="/userInfo/checkRegist.html"/>","registname="+registname,function(data,statusText)
			{
				if(data=='yes')
					{
					$('#show').html("<font color='red'>用户名已经存在</font>");
					}
				
			},"html");
}

function validate()
{
	
	var registname = $('#registname').val();
	var password = $("#password").val();
	var passwordag = $("#passwordag").val();
	
	$('#show').html("");
	$('#show1').html("");
	$('#show2').html("");
	checkRegist();
	
	if (registname=="")
		{
		$('#show').html("<font color='red'>用户名不能为空</font>");
		return;
		}
	else if (password=="")
		{
		$('#show1').html("<font color='red'>密码不能为空</font>");
		return;
		}
	else if (passwordag=="")
		{
		$('#show2').html("<font color='red'>密码不能为空</font>");
		return;
		}
	else if (passwordag!=password)
		{
		$('#show2').html("<font color='red'>两次密码不一致</font>");
		return;
		}
}

function regist()
{
	validate();
	var s =  $('#show').html();
	var s1 = $('#show1').html();
	var s2 = $('#show2').html();
	var registname = $('#registname').val();
	var password = $("#password").val();

	if(s==""&&s1==""&&s2=="")
		{
		$.post("<c:url value="/userInfo/regist.html"/>","registname="+registname+"&password="+password,
			function show1(data,statusText){
			$.messager.show({
				title:'My Title',
				msg:data,
				showType:'show'
			});
		},"html");
		$('#wregist').window('close');
		}
	
}

</script>

</head>
<body>
<img src="<c:url value="/ico/egg.jpg"/>" height="50"><font class="thick">虾扯淡2013</font>
<div class="demo-info">
	<div class="demo-tip icon-tip"></div>
	<div>请选择到您想去的版块</div>
</div>	
	
<a href="<c:url value="/userInfo.html"/>" class="easyui-linkbutton" >看看都有谁</a>
<a href="<c:url value="/forum.html"/>" class="easyui-linkbutton" >来扯淡吧</a>
<a href="<c:url value="/balance.html"/>" class="easyui-linkbutton" >我的钱到哪儿去了</a>
<a href="<c:url value="/plan.html"/>" class="easyui-linkbutton" >我的计划</a>
<a href="<c:url value="/remind.html"/>" class="easyui-linkbutton" >提醒我一下</a>
<a href="<c:url value="/map.html"/>" class="easyui-linkbutton" >我从哪里来</a>
<%
	User u=(User)request.getAttribute("user");
	if(u!=null)
	{
		out.print("<font color='red'>"+u.getUsername()+"欢迎回来，您的积分是"+u.getCredit()+"</font>");
	}
	User u2 = (User)session.getAttribute("user");
%>

<%
if(u2==null)
{
%>
<a href="#" class="easyui-linkbutton" onclick="open1()">登陆</a>
<a href="#" class="easyui-linkbutton" onclick="open2()" >注册</a>
<%
}%>

<%
String logonfirst =(String) request.getAttribute("logonfirst");
if(logonfirst!=null)
{
	out.println("<font color='red'>请先登录!</font>");
}
%>

<c:if test="${!empty error }">
 	<font color="red"><c:out value="${error}"></c:out></font>
</c:if> 
<br>
<br>
<div id="wlogin" class="easyui-window" data-options="title:'用户登陆',closed:true" style="width:300px;height:250px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'center',border:false" style="padding:10px;background:#fff;border:1px solid #ccc;">
			<!-- 表单-->
			<div style="background:#fafafa;padding:10px;width:200px;height:100px;">
	    	<form id="ff" method="post" novalidate action="<c:url value="/forum/loginCheck.html"/>">
	        <div>
	            <label for="name">用户名:</label>
	            <input class="easyui-validatebox"  type="text" name="userName" data-options="required:true"></input>
	        </div>
	        <div>
	            <label for="password">密码:</label>
	            <input class="easyui-validatebox" type="password" name="passWord"></input>
	        </div>
	    	</form>
	    	</div>
	    	</div>
	    	<!-- 表单完-->
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:login()">登陆</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:close1()">取消</a>
			</div>
		</div>
</div>
<div id="wregist" class="easyui-window" data-options="title:'用户注册',closed:true" style="width:300px;height:250px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'center',border:false" style="padding:10px;background:#fff;border:1px solid #ccc;">
			<!-- 表单-->
			<div style="background:#fafafa;padding:10px;width:200px;height:100px;">
	    	<form id="ff" method="post" novalidate action="<c:url value="/userInfo/regist.html"/>">
	        <div>
	            <label for="name">用户名:</label>
	            <input class="easyui-validatebox" id="registname" type="text" name="userName" data-options="required:true" onblur="checkRegist()"></input>
	            <div id="show"></div>
	        </div>
	        <div>
	            <label for="password">密码:</label>
	            <input class="easyui-validatebox" type="password" id="password" name="passWord" onblur="validate()"></input>
	       		<div id="show1"></div>
	        </div>
	        <div>
	            <label for="passwordag">再次输入密码:</label>
	            <input class="easyui-validatebox" type="password" id="passwordag" onblur="validate()"></input>
	        	<div id="show2"></div>
	        </div>
	    	</form>
	    	</div>
	    	</div>
	    	<!-- 表单完-->
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:regist()">注册</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:close2()">取消</a>
			</div>
		</div>
</div>
<%@include file="botton.jsp" %>
<div style="float:bottom;">
<img src="<c:url value="/ico/front.jpg"/>" width="100%">
</div>


</body>
</html>